package com.cuz.daileetcode;

import java.util.Arrays;
import java.util.Scanner;

public class Day24 {
    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);

        String str = in.nextLine();
        String[] line = str.split(",");
        int p = Integer.parseInt(in.nextLine());
        in.close();
        int[] ints = new int[line.length];
        for (int index = 0; index < line.length; index++) {
            ints[index]=Integer.parseInt(line[index]);
        }
        Arrays.sort(ints);
        int sum = 0, count = 0;
        for (Integer i : ints) {
            if (sum + i <= p) {
                sum += i;
                count++;
            } else {
                break;
            }
        }
        System.out.println(count);
    }
}
